package com.linq.cool.sdk.utils;


import com.linq.cool.qqbot.myqq.utils.regex.RegexRule;
import com.linq.cool.qqbot.myqq.utils.regex.RegexUtils;
import com.linq.cool.sdk.enums.MyQQRobotCommandEnum;
import org.springframework.util.StringUtils;

/**
 * @author: yqlin
 * @date: 2021/7/4 22:30
 * @description: 用来处理qq群组内的信息
 */
public class MyQQUtil {

    /**
     * 判断是否发送给机器人
     *
     * @param receiveMessage 接收到的信息
     *
     * @return true: 是
     */
    public static boolean isSendMessageToRobot(String receiveMessage) {
        return MyQQRobotCommandEnum.GROUP_AT_MEMBER_COMMAND.getPattern().matcher(receiveMessage).find();
    }

    /**
     * 解析出指定人的QQ
     *
     * @param receiveMessage 接收到的信息
     *
     * @return 指定人的qq
     */
    public static String parseQQ(String receiveMessage) {
        if (isSendMessageToRobot(receiveMessage)) {
            return RegexUtils.parse(receiveMessage, new RegexRule.Builder(MyQQRobotCommandEnum.GROUP_AT_MEMBER_COMMAND.getPattern().pattern(), "\\[@", "[0-9]\\]").build());
        } else {
            return null;
        }
    }

    /**
     * 判断是否是好友下载文件指令
     *
     * @param receiveMessage 接收到的信息
     *
     * @return true: 是
     */
    @Deprecated
    public static boolean isFriendDownloadCommand(String receiveMessage) {
        return MyQQRobotCommandEnum.FRIEND_DOWNLOAD_FILE_COMMAND.getPattern().matcher(receiveMessage).find();
    }

    /**
     * 判断是否是好友下载文件指令
     *
     * @param receiveMessage 接收到的信息
     *
     * @return true: 是
     */
    @Deprecated
    public static boolean isGroupDownloadCommand(String receiveMessage) {
        return MyQQRobotCommandEnum.GROUP_DOWNLOAD_FILE_COMMAND.getPattern().matcher(receiveMessage).find();
    }

    /**
     * 判断是否是下载指令
     *
     * @param receiveMessage 接收到的信息
     */
    @Deprecated
    public static boolean isDownloadCommand(String receiveMessage) {
        return MyQQRobotCommandEnum.DOWNLOAD_FILE_COMMAND.getPattern().matcher(receiveMessage).find();
    }


    @Deprecated
    public static String parseDownloadCommandFileName(String receiveMessage) {
        String parse = RegexUtils.parse(receiveMessage, new RegexRule.Builder(MyQQRobotCommandEnum.DOWNLOAD_FILE_COMMAND.getPattern().pattern(), 3, "\\)").build());
        return !StringUtils.containsWhitespace(parse) ? parse.substring(0, parse.length() - 1) : null;
    }

    public static void main(String[] args) {
        //        final String receiveMessage = "dd#考试系统图片a#";
        //        if (isFriendDownloadCommand(receiveMessage)) {
        //            System.out.println(parseDownloadCommandFileName(receiveMessage));
        //        } else {
        //            System.out.println("没有发消息");
        //        }
        //
        //        final String receiveMessage2 = "dd#考试系统图片#[@2719190494]";
        //        if (isGroupDownloadCommand(receiveMessage2)) {
        //            System.out.println(parseDownloadCommandFileName(receiveMessage2));
        //        } else {
        //            System.out.println("没有发消息");
        //        }

        //        final String receiveMessage3 = "dd#考试系统图片#[@2719190494]";
        //        if (isGroupDownloadCommand(receiveMessage3)) {
        //            System.out.println("进入isGroupDownloadCommand");
        //        } else if (isSendMessageToRobot(receiveMessage3)) {
        //            System.out.println("进入isSendMessageToRobot");
        //        }
    }
}
